package com.rockbb.common.dao;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;

public class CacheManagerBean {

	private CacheManager cacheManager;

	public CacheManagerBean() {}
	public CacheManagerBean(CacheManager cacheManager) {
		this.cacheManager = cacheManager;
	}

	public Cache get(String key) {
		return get(key, 1000, false, false, 180, 180, true);
	}

	public Cache get(String key, int size, int live) {
		return get(key, size, false, false, live, live, true);
	}

	public Cache get(String key, int size, int live, boolean create) {
		return get(key, size, false, false, live, live, create);
	}

	public Cache get(String key, int size, boolean toDisk, boolean eternal, int live, int idle, boolean create) {
		Cache cache = cacheManager.getCache(key);
		if (cache == null && create) {
			 cache = new Cache(key, size, toDisk, eternal, live, idle);
			 cacheManager.addCache(cache);
		}
		return cache;
	}

	public void shutdown() {
		cacheManager.shutdown();
	}
}
